


** File creating tables of descriptives on location choice by child status **
import delimited "$dir/Model/simulated_data/simulated_data_base_3.csv", clear
gen race = 2
tempfile blacks
save `blacks'


import delimited "$dir/Model/simulated_data/simulated_data_base_2.csv", clear
gen race = 1
append using `blacks'
export delimited "$dir/Model/simulated_data/simulated_data_base_combined.csv", replace novarn





/*
if `garrett' ==1{
global dir1 "C:\Users\Garrett\Documents\Work\Papers\Mig_Fam"
global dir2 "C:\Users\Garrett\Documents\Work\Papers\Mig_Fam"
}
*/


//if `sample'== 1{
import delimited "$model/utilities/estimation_sample.csv", clear
ren v1 uniqid
ren v2 year
ren v3 mu
ren v4 e
ren v5 m
ren v6 p
ren v7 l
ren v8 age
ren v9 x
ren v10 ac
ren v11 f
ren v12 lp_type
ren v13 h
ren v14 wage
ren v15 l_prime
drop if e == 2 & age<4
save "$temp/sample1", replace
//}


//if `sample' == 2{
	*** GARRETT: ADD NAME OF SIMULATION SAMPLE
import delimited "$model/simulated_data/simulated_data_base_combined.csv", clear
//import delimited "$model/simulated_data/simulated_data_base.csv", clear
ren v1 uniqid
ren v2 year
ren v3 mu
ren v4 e
ren v5 m
ren v6 p
ren v7 l
ren v8 age
ren v9 x
ren v10 ac
ren v11 f
ren v12 lp_type
ren v13 h
ren v14 wage
ren v15 l_prime
ren v16 sim 
ren v17 a_max
ren v18 tau
ren v19 util
ren v21 e_s
ren v22 race
bys uniqid sim: egen work_ever = max(h)
//fix up wages as we do in data
su wage, d
//replace wage = 30.99 if wage>30.99
replace wage = 7.25 if wage<7.25 & wage!=0 & wage!=. //


save "$temp/sample2", replace

//}

//garrett messed up some stuff when creating the estimation sample in terms of how variables are coded (indices vs. values). Adjust here.
forval i = 1/2{
	use "$temp/sample`i'", clear
	ds e m p f
	foreach var in `r(varlist)'{
		replace `var' = `var' - 1
	}
	replace ac = ac - 2
	replace x = x-1 //experience: 0 is the first index 
	replace age = age+21
	replace wage = 7.25 if wage<7.25 & wage!=0 & wage!=. //
	replace wage = . if wage == 0 //not observed if zero
	
	//variables to collapse: x, f, m (binary) h, wage, migration (binary)
	//collapse by education and age
	gen married = (m>0)
	gen mig = (l_prime<11)
	replace mig = . if l_prime == 99 //important adjustment
	local vars `"x f married h wage mig"'

	collapse (mean) `vars', by(e age) //collapse
	foreach var in `vars'{
		ren `var' `var'`i'
	}
	save "$temp/sample`i'_collapsed", replace
}



use "$temp/sample1_collapsed", clear
merge 1:1 e age using "$temp/sample2_collapsed", keep(match) nogen


local words `"Experience"'
local vars `"x"'
//local words `"Fertility"'
//local vars `"f"'
local counter 0

//make some plots
foreach var in `vars'{
    local counter `++counter'
	local word = word("`words'", `counter')
    line `var'1 age if e == 0, lc(navy) || ///
	line `var'2 age if e == 0, lc(navy) lp(dash) || ///
	line `var'1 age if e == 1, lc(maroon) || ///
	line `var'2 age if e == 1, lc(maroon) lp(dash) ///
	bgcolor(white) graphregion(color(white))  ///
	legend(lab(1 "No College, Data") lab(2 "No College, Model") lab(3 "College, Data") lab(4 "College, Model")) ytitle("`word'")
	graph export "$output/Figure_4a.png", replace
}


local words `"Wage"'
local vars `"wage"'
//local words `"Fertility"'
//local vars `"f"'
local counter 0

//make some plots
foreach var in `vars'{
    local counter `++counter'
	local word = word("`words'", `counter')
    line `var'1 age if e == 0, lc(navy) || ///
	line `var'2 age if e == 0, lc(navy) lp(dash) || ///
	line `var'1 age if e == 1, lc(maroon) || ///
	line `var'2 age if e == 1, lc(maroon) lp(dash) ///
	bgcolor(white) graphregion(color(white))  ///
	legend(lab(1 "No College, Data") lab(2 "No College, Model") lab(3 "College, Data") lab(4 "College, Model")) ytitle("`word'")
	graph export "$output/Figure_4b.png", replace
}



local words `"Married"'
local vars `"married"'
//local words `"Fertility"'
//local vars `"f"'
local counter 0

//make some plots
foreach var in `vars'{
    local counter `++counter'
	local word = word("`words'", `counter')
    line `var'1 age if e == 0, lc(navy) || ///
	line `var'2 age if e == 0, lc(navy) lp(dash) || ///
	line `var'1 age if e == 1, lc(maroon) || ///
	line `var'2 age if e == 1, lc(maroon) lp(dash) ///
	bgcolor(white) graphregion(color(white))  ///
	legend(lab(1 "No College, Data") lab(2 "No College, Model") lab(3 "College, Data") lab(4 "College, Model")) ytitle("`word'")
	graph export "$output/Figure_A3a.png", replace
}



local words `"Fertility"'
local vars `"f"'
//local words `"Fertility"'
//local vars `"f"'
local counter 0

//make some plots
foreach var in `vars'{
    local counter `++counter'
	local word = word("`words'", `counter')
    line `var'1 age if e == 0, lc(navy) || ///
	line `var'2 age if e == 0, lc(navy) lp(dash) || ///
	line `var'1 age if e == 1, lc(maroon) || ///
	line `var'2 age if e == 1, lc(maroon) lp(dash) ///
	bgcolor(white) graphregion(color(white))  ///
	legend(lab(1 "No College, Data") lab(2 "No College, Model") lab(3 "College, Data") lab(4 "College, Model")) ytitle("`word'")
	graph export "$output/Figure_5a.png", replace
}


drop if age<25 & e==1


exit



//end of dofile